package com.parking.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.parking.common.dao.impl.BaseDaoImpl;
import com.parking.dao.IFreeParkingDao;
import com.parking.entity.FreeParking;

@Repository("freeParkingDao")
public class FreeParkingDaoImpl extends BaseDaoImpl<FreeParking, Integer> implements IFreeParkingDao{

	private static Logger logger = Logger.getLogger(FreeParkingDaoImpl.class);
	
	@Override
	public List<FreeParking> findByKeywordAndAreacode(String keyword, int areacode, int pageSize,
			int pageNum) {
		String hql = "from FreeParking as freeParking where (freeParking.name like :keyword or freeParking.preferential like :keyword) and freeParking.areacode = :areacode order by freeParking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		return find(hql, params, pageSize, pageNum);
	}

	@Override
	public List<FreeParking> findByKeywordAndAreacode(String keyword, int areacode) {
		String hql = "from FreeParking as freeParking where (freeParking.name like :keyword or freeParking.preferential like :keyword) and freeParking.areacode = :areacode order by freeParking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		return find(hql, params);
	}

	@Override
	public long countByKeywordAndAreacode(String keyword, int areacode) {
		String hql = "select count(*) from FreeParking as freeParking where (freeParking.name like :keyword or freeParking.preferential like :keyword) and freeParking.areacode = :areacode order by freeParking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		return countAll(hql, params);
	}

	@Override
	public List<FreeParking> findByHotKey(int hotKey, int pageSize,
			int pageNum) {
		String hql = "from FreeParking as freeParking where freeParking.hotzone = :hotzone order by freeParking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("hotzone", hotKey);
		return find(hql, params, pageSize, pageNum);
	}

	@Override
	public long countByHotKey(int hotKey) {
		String hql = "select count(*) from FreeParking as freeParking where freeParking.hotzone = :hotzone order by freeParking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("hotzone", hotKey);
		return countAll(hql, params);
	}

}
